package com.qf.stream;

import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MainTest {
	public static void main(String[] args) {
		List<Employee> list =new ArrayList<Employee>();
		
		
		list.add(new Employee("S101","旺仔","男",15000,"空闲"));
		list.add(new Employee("S102","石头","女",25000,"空闲"));
		list.add(new Employee("S103","小明","男",3000,"忙碌"));
		list.add(new Employee("S104","小红","女",3500,"忙碌"));
		list.add(new Employee("S105","小王","男",3500,"离职"));
		list.add(new Employee("S106","小蓝","女",4000,"忙碌"));
		
		
		Stream<Employee> stream = list.stream();
		
		//1.查找并输出所有工资在6000元以上的男员工
		 //List<String> res = stream.filter(e->e.getEmpGender().equals("男")).filter(s->s.getEmpSalary()>6000).map(Employee::getEmpName).collect(Collectors.toList());    
		// System.out.println(res);
		 //2.显示工资最低的员工信息
		//List<String> res2 = stream.sorted().limit(1).map(Employee::toString).collect(Collectors.toList());
		//System.out.println(res2);
		
		//3.显示最高的工资
		//List<Integer> res = stream.sorted((emp1,emp2)->emp2.getEmpSalary()-(emp1.getEmpSalary())).limit(1).map(Employee::getEmpSalary).collect(Collectors.toList());
		//System.out.println(res);
		
//		int res = stream.map(Employee::getEmpSalary).max((a,b)->a-b).get();
//		System.out.println(res);
		//4.统计所有员工工资的平均值
		

		//double res2 =stream.collect(Collectors.averagingDouble(Employee::getEmpSalary));
		//System.out.println(res2);
		
		//5.显示目前处于休闲状态的员工人数
		//int res2 = stream.filter(s->s.getEmpStatus().equals("空闲")).collect(Collectors.toList()).size();
		//System.out.println(res2);
		
		//6.查找所有离职员工的员工姓名并显示
		//List<String> res= stream.filter(s->s.getEmpStatus().equals("离职")).map(Employee::getEmpName).collect(Collectors.toList());
		
		//System.out.println(res);
		
		
		//7.查找所有姓王的员工并收集到一个set集合中
		//boolean set = stream.map(Employee::getEmpName).collect(Collectors.toSet()).contains("w");
		
		//Set<String> set = stream.filter(s->s.getEmpName().contains("王")).map(Employee::getEmpName).collect(Collectors.toSet());
		
		//System.out.println(set);
		//8.按照员工的状态信息对所有员工进行分组操作，并得到一个Map集合，遍历这个结果输出每种状态的各自人数
		
		Map<String, List<Employee>> res = stream.collect(Collectors.groupingBy(Employee::getEmpStatus));
		
		for (String s : res.keySet()) {
			System.out.println(res.get(s));
		}
	}

}
